<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.global.js"></script>
</head>

<body>
    <div id="app">
        {{fullName}}
        <hr>
        {{userInput}}
        <input type="text" v-model="userInput">
        <hr>
        <button @click="fullName = userInput">设置名字</button>
    </div>

    <script>
        const app = {
            data() {
                return {
                    firstName: "john",
                    lastName: "smith",
                    userInput: "你妹"
                }
            },
            computed: {
                fullName: {
                    // getter
                    get() {
                        console.log("getter");
                        return this.firstName + ' ' + this.lastName
                    },

                    // setter
                    set(newValue) {
                        console.log("setter");
                        const names = newValue.split(' ')
                        this.firstName = names[0]
                        this.lastName = names[names.length - 1]
                    }
                }
            }
        }
        Vue.createApp(app).mount("#app")
    </script>
</body>

</html>